package com.doucat.support.component.permission;

import android.app.Activity;

import androidx.fragment.app.Fragment;

/**
 * -----------------------------------------------------------------
 * Copyright (C) 2014-2016, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * File: PermissionManager.java
 * Author: wfy
 * Version: V100R001C01
 * Create: 2020/12/17 15:15
 * Changes (from 2020/12/17)
 * -----------------------------------------------------------------
 * 2020/12/17 : Create PermissionManager.java (wfy);
 * -----------------------------------------------------------------
 */
public class PermissionProxy implements PermissionRequester {
    protected String TAG=getClass().getSimpleName();
    private PermissionRequester permissionRequester;

    public PermissionProxy(int type, Object target) {
        if(type==ACTIVITY){
            permissionRequester =new ActivityPermission((Activity) target);
        }else {
            permissionRequester =new FragmentPermission((Fragment) target);
        }
    }

    @Override
    public void requestPermissions(String[] permissions) {
        permissionRequester.requestPermissions(permissions);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        permissionRequester.onRequestPermissionsResult(requestCode,permissions,grantResults);
    }

    @Override
    public void setPermissionListener(PermissionListener permissionListener) {
        permissionRequester.setPermissionListener(permissionListener);
    }
}
